//
//  YWMissionManager.m
//  maintain
//
//  Created by 郑想 on 15/11/5.
//  Copyright © 2015年 ewin. All rights reserved.
//

#import "WMHttpTool.h"
#import "MJExtension.h"
#import "YWApartment.h"
#import "YWBuilding.h"
#import "YWBuildingManager.h"
#import "YWCommonTool.h"
#import "YWDBTool.h"
#import "YWEquipment.h"
#import "YWEquipmentManager.h"
#import "YWEquipmentTroubleRecord.h"
#import "YWFloor.h"
#import "YWHandler.h"
#import "YWLocation.h"
#import "YWMacro.h"
#import "YWConst.h"
#import "YWMission.h"
#import "YWMissionManager.h"
#import "YWMissionRuleResult.H"
#import "YWNotifyManager.h"
#import "YWPicture.h"
#import "YWPushManager.h"
#import "YWQrcodeInfo.h"
#import "YWResourceManager.h"
#import "YWEquipmentFieldRecord.h"
#import "YWLoginUser.h"
#import "YWLoginTool.h"
#import "YWNoQrcodeRights.h"
#import "YWCirculationManager.h"
#import "YWEquipmentType.h"
#import "YWKeepWatchMissionManager.h"
#import "YWInspectionMissionManager.h"
#import "YWDetectAndUpkeepManager.h"
#import "YWEwinManager.h"
#import "YWFunctionManager.h"
#import "YWFunctionModel.h"
#import "YWLogRecordTool.h"
#import "YWTroubleMissionModel.h"
#import "YWTroubleMissionManager.h"
#import "YWReportTroubleModel.h"
#import "YWReportTroubleManager.h"
#import "YWTroubleMissionDBManager.h"
#import <Bugly/Bugly.h>

@interface YWMissionManager ()
//@property (nonatomic, strong) dispatch_queue_t serialQueue;
@property (nonatomic, strong) dispatch_semaphore_t signal;
@end

@implementation YWMissionManager
YWSingletonM(Manager)

//- (dispatch_queue_t)serialQueue{
//    if (!_serialQueue) {
//        _serialQueue = dispatch_queue_create("uploadTaskserialQueue", DISPATCH_QUEUE_SERIAL); //创建上传串行队列
//    }
//    return _serialQueue;
//}

- (dispatch_semaphore_t)signal{
    if (!_signal) {
        _signal = dispatch_semaphore_create(1);
    }
    return _signal;
}



- (BOOL)updatePostTroubleId:(YWReportTroubleModel *)reportTrouble uniqueTag:(NSString *)uniqueTag{
    return [[YWDBTool shareDBTool] updatePostTroubleId:reportTrouble uniqueTag:uniqueTag];
}



- (NSArray*)picturesWithEquipmentId:(NSString*)equipmentId pictureTroubleType:(YWPictureTroubleType)type
{
    return [[YWDBTool shareDBTool] picturesWithEquipmentId:equipmentId pictureTroubleType:type];
}

//- (NSArray*)picturesWithMissionId:(NSInteger)missionId maintenanceType:(NSInteger)maintenanceTypeId equipmentId:(NSInteger)equipmentId
//{
//    return [[YWDBTool shareDBTool] picturesWithMissionId:missionId maintenanceType:maintenanceTypeId equimentId:equipmentId];
//}

- (NSArray*)picturesWithRecordId:(NSInteger)recordId maintenanceType:(NSInteger)maintenanceTypeId
{
    return [[YWDBTool shareDBTool] picturesWithRecordId:recordId maintenanceType:maintenanceTypeId];
}

- (NSArray*)picturesWithTroubleRecordId:(NSInteger)recordId pictureTroubleType:(YWPictureTroubleType)type
{
    return [[YWDBTool shareDBTool] troublePicturesWithRecordId:recordId pictureTroubleType:type];
}

- (NSArray*)picturesWithTroubleMissionId:(NSInteger)missionId pictureTroubleType:(YWPictureTroubleType)type
{
    return [[YWDBTool shareDBTool] picturesWithTroubleMissionId:missionId pictureTroubleType:type];
}

- (BOOL)updateMissionMaintenceRecordUploadStatus:(YWEquipmentMaintenanceRecordUploadStatus)uploadStatus recordId:(NSInteger)recordId maintenanceTypeId:(YWMaintenanceType)maintenceTypeId
{
    BOOL result = NO;
    switch (maintenceTypeId) {
    case YWMaintenanceTypePatrol:
//        result = [[YWDBTool shareDBTool] updateEquipmentPatrolRecordUploadStatus:uploadStatus recordId:recordId];
        break;
    case YWMaintenanceTypeDetection:
        result = [[YWDBTool shareDBTool] updateEquipmentDetectionRecordUploadStatus:uploadStatus recordId:recordId];
        break;
    case YWMaintenanceTypeUpkeep:
        result = [[YWDBTool shareDBTool] updateEquipmentUpkeepRecordUploadStatus:uploadStatus recordId:recordId];
        break;
    case YWMaintenanceTypeTrouble:
        result = [[YWDBTool shareDBTool] updateEquipmentTroubleRecordUploadStatus:uploadStatus recordId:recordId];
        break;
    default:
        break;
    }
    return result;
}



- (NSArray*)uploadFailedRecordsWithMaintenanceType:(NSInteger)maintenanceType{
    return [[YWDBTool shareDBTool] uploadFailedRecordsWithMaintenanceType:maintenanceType];
}



- (BOOL)updateEquipmentFieldRecords:(NSArray*)equipmentFieldRecords{
    return [[YWDBTool shareDBTool] updateEquipmentFieldRecords:equipmentFieldRecords];
}

- (NSArray *)equipmentFieldRecordsWithUniqueTag:(NSString *)uniqueTag maintenanceTypeId:(NSInteger)maintenanceTypeId{
    return [[YWDBTool shareDBTool] equipmentFieldRecordsWithUniqueTag:uniqueTag maintenanceTypeId:maintenanceTypeId];
}

-(NSArray *)maintenanceRecordsWithEquipmentId:(NSString *)equipmentId andPage:(NSInteger)page{
    return [[YWDBTool shareDBTool] maintenanceRecordsWithEquipmentId:equipmentId andPage:page];
}

- (NSArray*)keepWatchAndInspectRecordsWithLocationId:(NSInteger)locationId andPage:(NSInteger)page{
    return [[YWDBTool shareDBTool] keepWatchAndInspectRecordsWithLocationId:locationId andPage:page];
}
- (NSArray*)keepWatchAndInspectRecordsInLedgerLocationDetailWithLocationId:(NSInteger)locationId andPage:(NSInteger)page type:(NSInteger)type{
    return [[YWDBTool shareDBTool] keepWatchAndInspectRecordsInLedgerLocationDetailWithLocationId:locationId andPage:page type:type];
}




- (NSArray *)patrolRecordsWithEquipmentId:(NSString*)equipmentId andPage:(NSInteger)page{
    return [[YWDBTool shareDBTool] patrolRecordsWithEquipmentId:equipmentId andPage:page];
}

- (BOOL)saveBuildingMembersWithJson:(NSArray *)buildingMembersJsonArray{
    return [[YWDBTool shareDBTool] saveBuildingMembersWithJson:buildingMembersJsonArray];
}

- (BOOL)saveOrganizationMembersWithArray:(NSArray *)organizationMembers{
    return [[YWDBTool shareDBTool] saveOrganizationMembersWithArray:organizationMembers];
}

- (NSArray*)projectMember
{
    return [[YWDBTool shareDBTool] allHandler];
}



- (BOOL)setUploadFailWithMission:(id)mission
{
    return [[YWDBTool shareDBTool] setUploadFailWithMission:mission];
}


- (YWMissionScanQrcodeStatus)judgeScanMatchMission:(id)mission qrcodeId:(NSString*)qrcodeId orNoScanQrcodeLocationId:(NSInteger)noScanQrcodeLocationId
{
    __block YWMissionScanQrcodeStatus status = YWMissionScanQrcodeStatusUnMatch;
//    NSInteger locationId = [[YWEquipmentManager shareManager] locationIdWithQrcodeId:qrcodeInfo.qrcodeID];
    NSInteger equipmentTypeId = 0;
    NSInteger maintenanceTypeId = 0;
    if ([mission isKindOfClass:[YWTroubleMissionModel class]]) {
        YWTroubleMissionModel *troubleMission = (YWTroubleMissionModel*)mission;
        equipmentTypeId = troubleMission.trouble.equipment.equipmentTypeId;
        maintenanceTypeId = YWMaintenanceTypeTrouble;
        if ([qrcodeId isEqualToString:troubleMission.trouble.qrcodeId] || [qrcodeId isEqualToString:troubleMission.trouble.equipment.qrcodeId]) {
            return YWMissionScanQrcodeStatusMatch;
        }
    }else {
        YWMaintenanceMission *maintenanceMission = (YWMaintenanceMission*)mission;
        equipmentTypeId = maintenanceMission.equipmentTypeId;
        maintenanceTypeId = maintenanceMission.maintenanceTypeId;
        status = YWMissionScanQrcodeStatusMatch;
    }

    if (status == YWMissionScanQrcodeStatusMatch) {
        status = YWMissionScanQrcodeStatusUnMatch;

        //NSArray* qrcodeEquipmentInfos = [[YWEquipmentManager shareManager] qrcodeEquipmentInfos:qrcodeId];
        NSArray* qrcodeEquipmentInfos = [[YWEquipmentManager shareManager] qrcodeEquipmentInfos:qrcodeId orLocationId:noScanQrcodeLocationId equipmentTypeId:equipmentTypeId];
        [qrcodeEquipmentInfos enumerateObjectsUsingBlock:^(YWQrcodeEquipmentInfo* _Nonnull qrcodeEquipmentInfo, NSUInteger idx, BOOL* _Nonnull stop) {
            if (qrcodeEquipmentInfo.equipmentTypeId == equipmentTypeId) {
                if (maintenanceTypeId == YWMaintenanceTypeTrouble) {
                    status = YWMissionScanQrcodeStatusMatch;
                    *stop = YES;
                }else {
                    NSArray *qrcodeEquipments = [[YWEquipmentManager shareManager] equipmentWithQrcodeId:qrcodeId orLocationId:noScanQrcodeLocationId equipmentTypeId:equipmentTypeId];
                    NSArray *missionEquipments = nil;
                    YWMaintenanceMission *maintenanceMission = (YWMaintenanceMission*)mission;
                    if (maintenanceMission.equipments.count>0) {//maintenanceMission.type == YWMissionTypeAuto
                        missionEquipments = maintenanceMission.equipments;
                        [qrcodeEquipments enumerateObjectsUsingBlock:^(YWEquipment*  _Nonnull equipment, NSUInteger idx, BOOL * _Nonnull stop) {
                            if (missionEquipments) {
                                NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"%K == %@", @"equipmentId", equipment.equipmentId];
                                NSArray *array = [missionEquipments filteredArrayUsingPredicate:searchPredicate];
                                if (array.count>0) {
                                    YWEquipmentMaintenanceRecord *record = [YWDetectAndUpkeepManager maintenanceRecordWithMission:maintenanceMission equipmentId:equipment.equipmentId];
                                    if (record == nil) {
                                        status = YWMissionScanQrcodeStatusMatch;
                                        *stop = YES;
                                    }else{
                                        status = YWMissionScanQrcodeStatusSubmited;
                                    }
                                }
                            }
                        }];
                    }else{
                        [qrcodeEquipments enumerateObjectsUsingBlock:^(YWEquipment*  _Nonnull equipment, NSUInteger idx, BOOL * _Nonnull stop) {
//                            if (missionEquipments) {
//                                NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"%K == %@", @"equipmentId", equipment.equipmentId];
//                                NSArray *array = [missionEquipments filteredArrayUsingPredicate:searchPredicate];
//                                if (array.count==0) {
//                                }
//                            }
                            if ([equipment.buildingId isEqualToString:maintenanceMission.buildingId]) {
                                YWEquipmentMaintenanceRecord *record = [YWDetectAndUpkeepManager maintenanceRecordWithMission:maintenanceMission equipmentId:equipment.equipmentId];
                                if (record == nil) {
                                    status = YWMissionScanQrcodeStatusMatch;
                                    *stop = YES;
                                }else{
                                    status = YWMissionScanQrcodeStatusSubmited;
                                }
                            }
                        }];
                    }
                }
                *stop = YES;
            }
        }];
    }
    return status;
}


- (NSArray*)matchAllTypeMissionsWithQrcodeId:(NSString*)qrcodeId{
    NSMutableArray *matchMission = [NSMutableArray array];
    NSArray * functionIdArray = @[@(YWFunctionIdDetection),@(YWFunctionIdUpkeep),@(YWFunctionIdRepair),@(YWFunctionIdKeepWatch),@(YWFunctionIdInspection)];
    NSArray* functionArray = [[YWFunctionManager shareManager] getFunctionArrayWithFunctionIdArray:functionIdArray];
    NSArray* missions;
    NSArray *inspectionMissions;
    NSArray *keepWatchMissions;
    for (YWFunctionModel * function in functionArray) {
        switch (function.functionId) {
            case YWFunctionIdDetection:
                missions = [[YWMissionManager shareManager] missionsWithQrcodeID:qrcodeId orLocationId:0 andMaintenanceTypeId:YWMaintenanceTypeDetection];
                [matchMission addObjectsFromArray:missions];
                break;
            case YWFunctionIdUpkeep:
                missions = [[YWMissionManager shareManager] missionsWithQrcodeID:qrcodeId orLocationId:0 andMaintenanceTypeId:YWMaintenanceTypeUpkeep];
                [matchMission addObjectsFromArray:missions];
                break;
            case YWFunctionIdRepair:
                missions = [[YWMissionManager shareManager] missionsWithQrcodeID:qrcodeId orLocationId:0 andMaintenanceTypeId:YWMaintenanceTypeTrouble];
                [matchMission addObjectsFromArray:missions];
                break;
            case YWFunctionIdKeepWatch:
                inspectionMissions = [[YWInspectionMissionManager shareManager] matchInspectionMissionsWithQrcodeID:qrcodeId orLocationId:0];
                [matchMission addObjectsFromArray:inspectionMissions];
                break;
            case YWFunctionIdInspection:
                keepWatchMissions = [[YWKeepWatchMissionManager shareManager] matchKeepWatchMissionsWithQrcodeID:qrcodeId orLocationId:0];
                [matchMission addObjectsFromArray:keepWatchMissions];
                break;
            default:
                break;
        }
    }
      return matchMission;
}

- (NSArray *)matchAllTypeMissionsWithLocationId:(NSInteger)locationId{
    NSMutableArray *matchMission = [NSMutableArray array];
//    //维修，检测，保养任务
//    NSArray* missions = [[YWMissionManager shareManager] missionsWithQrcodeId:nil orLocationId:locationId];
    
//    NSPredicate *searchPredicate = nil;
    NSArray *array = nil;
    //维修
    NSArray * functionIdArray = @[@(YWFunctionIdRepair),@(YWFunctionIdDetection),@(YWFunctionIdUpkeep),@(YWFunctionIdInspection),@(YWFunctionIdKeepWatch)];
    NSArray* functionArray = [[YWFunctionManager shareManager] getFunctionArrayWithFunctionIdArray:functionIdArray];
    for (YWFunctionModel * function in functionArray) {
        if ([function.functionName isEqualToString:@"维修"]) {
//            searchPredicate = [NSPredicate predicateWithFormat:@"%K = %ld", @"maintenanceTypeId", YWMaintenanceTypeTrouble];
//            array = [[missions filteredArrayUsingPredicate:searchPredicate] mutableCopy];
//            if (array.count>0) {
                NSInteger value = [[[NSUserDefaults standardUserDefaults] objectForKey:KYWNoQrcodeTypeFixTroubleKey] integerValue];
                if (value!=1) {
                    array = [self missionsWithQrcodeID:nil orLocationId:locationId andMaintenanceTypeId:YWMaintenanceTypeTrouble];
                    [matchMission addObjectsFromArray:array];
                }
//            }
        }else if ([function.functionName isEqualToString:@"检测"]) {
//            searchPredicate = [NSPredicate predicateWithFormat:@"%K = %ld", @"maintenanceTypeId", YWMaintenanceTypeDetection];
//            array = [[missions filteredArrayUsingPredicate:searchPredicate] mutableCopy];
//            if (array.count>0) {
                NSInteger value = [[[NSUserDefaults standardUserDefaults] objectForKey:KYWNoQrcodeTypeDetectionKey] integerValue];
                if (value!=1) {
                    array = [self missionsWithQrcodeID:nil orLocationId:locationId andMaintenanceTypeId:YWMaintenanceTypeDetection];
                    [matchMission addObjectsFromArray:array];
                }
//            }
        }else if ([function.functionName isEqualToString:@"保养"]) {
//            searchPredicate = [NSPredicate predicateWithFormat:@"%K = %ld", @"maintenanceTypeId", YWMaintenanceTypeUpkeep];
//            array = [[missions filteredArrayUsingPredicate:searchPredicate] mutableCopy];
//            if (array.count>0) {
                NSInteger value = [[[NSUserDefaults standardUserDefaults] objectForKey:KYWNoQrcodeTypeUpkeepKey] integerValue];
                if (value!=1) {
                    array = [self missionsWithQrcodeID:nil orLocationId:locationId andMaintenanceTypeId:YWMaintenanceTypeUpkeep];
                    [matchMission addObjectsFromArray:array];
                }
//            }
        }else if ([function.functionName isEqualToString:@"巡查"]) {
            NSInteger value = [[[NSUserDefaults standardUserDefaults] objectForKey:KYWNoQrcodeTypeInspectionKey] integerValue];
            if (value!=1) {
                NSArray *inspectionMissions = [[YWInspectionMissionManager shareManager] matchInspectionMissionsWithQrcodeID:nil orLocationId:locationId];
                [matchMission addObjectsFromArray:inspectionMissions];
            }
        }else if ([function.functionName isEqualToString:@"巡更"]) {
            NSInteger value = [[[NSUserDefaults standardUserDefaults] objectForKey:KYWNoQrcodeTypeKeepWatchKey] integerValue];
            if (value!=1) {
                NSArray *keepWatchMissions = [[YWKeepWatchMissionManager shareManager] matchKeepWatchMissionsWithQrcodeID:nil orLocationId:locationId];
                [matchMission addObjectsFromArray:keepWatchMissions];
            }
        }
    }
    return matchMission;
}

- (NSArray*)missionsWithQrcodeId:(NSString*)qrcodeId orLocationId:(NSInteger)locationId
{
    NSArray* missions = [[YWDBTool shareDBTool] unfinishedMissionsWithQrcodeID:qrcodeId orLocationId:locationId];
    NSMutableArray* resultMission = [NSMutableArray array];
    NSInteger equipmentTypeId = 0;
    for (id object in missions) {
        if ([object isKindOfClass:[YWTroubleMissionModel class]]) {
            YWTroubleMissionModel *troubleMissionModel = (YWTroubleMissionModel*)object;
            //equipmentTypeId = troubleMissionModel.trouble.equipment.equipmentTypeId;
            YWEquipmentTroubleRecord* record = [[YWTroubleMissionManager shareManager] troubleRecordWithMissionId:troubleMissionModel.trouble.troubleId];
            if (record == nil && ![resultMission containsObject:troubleMissionModel]) {
                [resultMission addObject:troubleMissionModel];
            }
        }else{
            YWMaintenanceMission *maintenanceMission = (YWMaintenanceMission*)object;
            equipmentTypeId = maintenanceMission.equipmentTypeId;
            NSMutableArray* equipments = [NSMutableArray array];
            if (maintenanceMission.equipments.count>0) {//missionType == YWMissionTypeAuto
                YWMaintenanceMission *maintenanceMission = (YWMaintenanceMission*)object;
                NSArray *missionEquipments = maintenanceMission.equipments;
                NSArray *allQrcodeEquipments = [[YWEquipmentManager shareManager] equipmentWithQrcodeId:qrcodeId orLocationId:locationId equipmentTypeId:equipmentTypeId];
                [allQrcodeEquipments enumerateObjectsUsingBlock:^(YWEquipment*  _Nonnull equipment, NSUInteger idx, BOOL * _Nonnull stop) {
                    NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"%K == %@", @"equipmentId", equipment.equipmentId];
                    NSArray *array = [missionEquipments filteredArrayUsingPredicate:searchPredicate];
                    if (array.count==1) {
                        [equipments addObjectsFromArray:array];
                    }
                }];
            }else{
                [equipments addObjectsFromArray:[[YWEquipmentManager shareManager] equipmentWithQrcodeId:qrcodeId orLocationId:locationId equipmentTypeId:equipmentTypeId]];
            }
            [equipments enumerateObjectsUsingBlock:^(YWEquipment*  _Nonnull equipment, NSUInteger idx, BOOL * _Nonnull stop) {
                YWEquipmentMaintenanceRecord* record = [YWDetectAndUpkeepManager maintenanceRecordWithMission:maintenanceMission equipmentId:equipment.equipmentId];
                if (record == nil && ![resultMission containsObject:object]) {
                    [resultMission addObject:object];
                    *stop = YES;
                }
            }];
        }
        
    }
    return resultMission;
}

- (NSArray*)missionsWithQrcodeID:(NSString*)qrcodeID orLocationId:(NSInteger)locationId andMaintenanceTypeId:(NSInteger)maintenanceTypeId{
    NSArray* missions = [[YWDBTool shareDBTool] unfinishedMissionsWithQrcodeID:qrcodeID orLocationId:locationId andMaintenanceTypeId:maintenanceTypeId];
    NSMutableArray* resultMission = [NSMutableArray array];
    NSInteger equipmentTypeId = 0;
    for (id object in missions) {
        if ([object isKindOfClass:[YWTroubleMissionModel class]]) {
//            YWTroubleMission *troubleMission = (YWTroubleMission*)object;
            YWTroubleMissionModel *troubleMissionModel = (YWTroubleMissionModel*)object;
            //equipmentTypeId = troubleMissionModel.trouble.equipment.equipmentTypeId;
            YWEquipmentTroubleRecord* record = [[YWTroubleMissionManager shareManager] troubleRecordWithMissionId:troubleMissionModel.trouble.troubleId];
            if (record == nil && ![resultMission containsObject:troubleMissionModel]) {
                [resultMission addObject:troubleMissionModel];
            }
        }else{
            YWMaintenanceMission *maintenanceMission = (YWMaintenanceMission*)object;
            equipmentTypeId = maintenanceMission.equipmentTypeId;
            NSMutableArray* equipments = [NSMutableArray array];
            if (maintenanceMission.equipments.count>0) {//missionType == YWMissionTypeAuto
                YWMaintenanceMission *maintenanceMission = (YWMaintenanceMission*)object;
                NSArray *missionEquipments = maintenanceMission.equipments;
                NSArray *allQrcodeEquipments = [[YWEquipmentManager shareManager] equipmentWithQrcodeId:qrcodeID orLocationId:locationId equipmentTypeId:equipmentTypeId];
                [allQrcodeEquipments enumerateObjectsUsingBlock:^(YWEquipment*  _Nonnull equipment, NSUInteger idx, BOOL * _Nonnull stop) {
                    NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"%K == %@", @"equipmentId", equipment.equipmentId];
                    NSArray *array = [missionEquipments filteredArrayUsingPredicate:searchPredicate];
                    if (array.count==1) {
                        [equipments addObjectsFromArray:array];
                    }
                }];
            }else{
                [equipments addObjectsFromArray:[[YWEquipmentManager shareManager] equipmentWithQrcodeId:qrcodeID orLocationId:locationId equipmentTypeId:equipmentTypeId]];
            }
            [equipments enumerateObjectsUsingBlock:^(YWEquipment*  _Nonnull equipment, NSUInteger idx, BOOL * _Nonnull stop) {
                YWEquipmentMaintenanceRecord* record = [YWDetectAndUpkeepManager maintenanceRecordWithMission:maintenanceMission equipmentId:equipment.equipmentId];
                if (record == nil && ![resultMission containsObject:object]) {
                    [resultMission addObject:object];
                    *stop = YES;
                }
            }];
        }
    }
    return resultMission;
}

- (NSArray*)missionsWithEquipmentId:(NSString*)equipmentId andMaintenanceTypeId:(NSInteger)maintenanceTypeId{
    return [[YWDBTool shareDBTool] missionsWithEquipmentId:equipmentId andMaintenanceTypeId:maintenanceTypeId];
}

- (BOOL)mofifyMissionStatusWithMissionId:(NSInteger)missionId maintenanceType:(YWMaintenanceType)typeId{
    return [[YWDBTool shareDBTool] mofifyMissionStatusWithMissionId:missionId maintenanceType:typeId];
}


- (BOOL)isExistRelWithTroubleId:(NSInteger)troubleId detailUniqueTag:(NSString*)detailUniqueTag{
    return [[YWDBTool shareDBTool] isExistRelWithTroubleId:troubleId detailUniqueTag:detailUniqueTag];
}
- (void)saveRecordAndPostTroubleRelWithtroubleId:(NSInteger)troubleId detailUniqueTag:(NSString*)detailUniqueTag{
    return [[YWDBTool shareDBTool] saveRecordAndPostTroubleRelWithtroubleId:troubleId detailUniqueTag:detailUniqueTag];
}
- (void)updateRecordAndPostTroubleRelTableUniqueTag:(NSString*)uniqueTag newTroubleId:(NSInteger)newTroubleId{
    return [[YWDBTool shareDBTool] updateRecordAndPostTroubleRelTableUniqueTag:uniqueTag newTroubleId:newTroubleId];
}

- (NSArray *)troubleIdArrayWithDetailUniqueTag:(NSString *)detailUniqueTag{
    return [[YWDBTool shareDBTool] troubleIdArrayWithDetailUniqueTag:detailUniqueTag];
}

- (NSArray *)postTroubleArrayWithDetailUniqueTag:(NSString *)detailUniqueTag{
    return [[YWDBTool shareDBTool] postTroubleArrayWithDetailUniqueTag:detailUniqueTag];
}

@end
